package com.avic.common.util.lang;

import com.avic.common.util.ex.BizErrorCode;
import com.avic.common.util.ex.BizException;
import lombok.extern.slf4j.Slf4j;

/**
 * @author: huangsheng
 * @date: 2018/4/11
 */
@Slf4j
public class CommonServiceExecuteTemplate implements ServiceExecuteTemplate {

    @Override
    public <T extends BaseResponse> T executeService(T result, ServiceCallBack serviceCallBack) {
        try {
            serviceCallBack.check();
            serviceCallBack.doService();
        } catch (BizException be) {
            log.info("捕捉到业务异常 {}", be.getDescription());
            result.setCode(be.getErrorCodeEnum().getCode());
            result.setMessage(be.getDescription());
            result.setSuccess(false);
        } catch (Exception var14) {
            log.info("捕捉到未知异常 {}", var14.getMessage());
            result.setCode(BizErrorCode.UNKNOWN_ERROR.getCode());
            result.setMessage(var14.getMessage());
            result.setSuccess(false);
        }
        return result;
    }
}
